Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / core / datastore / src / commonMain / kotlin / org / meshtastic / core / datastore / BootloaderWarningDataSource.kt

Displaying Raw • Download

core/datastore/src/commonMain/kotlin/org/meshtastic/core/datastore/BootloaderWarningDataSource.kt bd2863243bab6eb213401d949839a2bc74dde7e2 (bd286324) Text, 2.79 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.datastore

Tff7b72import T7ee787androidx.datastore.preferences.core.edit
Tff7b72import T7ee787androidx.datastore.preferences.core.stringPreferencesKey
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.flow.first
Tff7b72import T7ee787kotlinx.coroutines.flow.map
Tff7b72import T7ee787kotlinx.serialization.SerializationException
Tff7b72import T7ee787kotlinx.serialization.json.Json
Tff7b72import T7ee787org.koin.core.annotation.Single
Tff7b72import T7ee787org.meshtastic.core.datastore.di.CorePreferencesDataStore

Tf0883e@Single
Tff7b72open Tff7b72class T56d364BootloaderWarningDataSourceTb4b4b4(Tff7b72private Tff7b72val Te6edf3dataStoreTb4b4b4: Te6edf3CorePreferencesDataStoreTb4b4b4) Tb4b4b4{

Tff7b72private Tff7b72object T56d364PreferencesKeys Tb4b4b4{
Tff7b72val Te6edf3DISMISSED_BOOTLOADER_ADDRESSES Tff7b72= Te6edf3stringPreferencesKeyTb4b4b4(Ta5d6ff"Ta5d6ffdismissed-bootloader-addressesTa5d6ff"Tb4b4b4)
Tb4b4b4}

Tff7b72private Tff7b72val Te6edf3dismissedAddressesFlow Tff7b72=
Te6edf3dataStoreTb4b4b4.Te6edf3dataTb4b4b4.Te6edf3map Tb4b4b4{ Te6edf3preferences Tff7b72-Tff7b72>
Tff7b72val Te6edf3jsonString Tff7b72= Te6edf3preferencesTff7b72[Te6edf3PreferencesKeysTb4b4b4.Te6edf3DISMISSED_BOOTLOADER_ADDRESSESTff7b72] Tff7b72?: Tff7b72returnTf0883e@map Te6edf3emptySetTb4b4b4(Tb4b4b4)

Te6edf3runCatching Tb4b4b4{ Te6edf3JsonTb4b4b4.Te6edf3decodeFromStringTff7b72<Te6edf3ListTff7b72<Tffa657StringTff7b72>Tff7b72>Tb4b4b4(Te6edf3jsonStringTb4b4b4)Tb4b4b4.Te6edf3toSetTb4b4b4(Tb4b4b4) Tb4b4b4}
Tb4b4b4.Te6edf3onFailure Tb4b4b4{ Te6edf3e Tff7b72-Tff7b72>
Tff7b72if Tb4b4b4(Te6edf3e Tff7b72is Te6edf3IllegalArgumentException Tff7b72|Tff7b72| Te6edf3e Tff7b72is Te6edf3SerializationExceptionTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffFailed to parse dismissed bootloader warning addresses, resetting preferenceTa5d6ff" Tb4b4b4}
Tb4b4b4} Tff7b72else Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffUnexpected error while parsing dismissed bootloader warning addressesTa5d6ff" Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4.Te6edf3getOrDefaultTb4b4b4(Te6edf3emptySetTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}

T8b949e/** Returns true if the bootloader warning has been dismissed for the given [address]. */
Tff7b72open Tff7b72suspend Tff7b72fun Td2a8ffisDismissedTb4b4b4(Te6edf3addressTb4b4b4: Tffa657StringTb4b4b4)Tb4b4b4: Tffa657Boolean Tff7b72= Te6edf3dismissedAddressesFlowTb4b4b4.Te6edf3firstTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3containsTb4b4b4(Te6edf3addressTb4b4b4)

T8b949e/** Marks the bootloader warning as dismissed for the given [address]. */
Tff7b72open Tff7b72suspend Tff7b72fun Td2a8ffdismissTb4b4b4(Te6edf3addressTb4b4b4: Tffa657StringTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3current Tff7b72= Te6edf3dismissedAddressesFlowTb4b4b4.Te6edf3firstTb4b4b4(Tb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3currentTb4b4b4.Te6edf3containsTb4b4b4(Te6edf3addressTb4b4b4)Tb4b4b4) Tff7b72return

Tff7b72val Te6edf3updated Tff7b72= Tb4b4b4(Te6edf3current Tff7b72+ Te6edf3addressTb4b4b4)Tb4b4b4.Te6edf3toListTb4b4b4(Tb4b4b4)
Te6edf3dataStoreTb4b4b4.Te6edf3edit Tb4b4b4{ Te6edf3preferences Tff7b72-Tff7b72>
Te6edf3preferencesTff7b72[Te6edf3PreferencesKeysTb4b4b4.Te6edf3DISMISSED_BOOTLOADER_ADDRESSESTff7b72] Tff7b72= Te6edf3JsonTb4b4b4.Te6edf3encodeToStringTb4b4b4(Te6edf3updatedTb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.11s